import React, {Component} from 'react';
import {Table} from 'antd';
import {Map} from 'react-amap';


class MapTest extends Component {
    constructor(props) {
        super(props);
        this.state = {
            listData: []
        };
        this.pushData = this.pushData.bind(this);
    }

    componentDidMount() {
        let dt = [1, 2, 3, 4, 5, 56, 6, 7];
        let listData = this.state.listData;
        for (let i = 0; i < dt.length; i++) {
            listData.push(this.pushData(i + 1, '通过预审资格的申请人名单', dt[i]))
        }
        listData.push(this.pushData(dt.length + 1, '资格评审结果生成时间', '--'));
        this.setState({
            listData: listData
        });
        console.log(listData)
    }

    pushData(key, title, data) {
        let json = {};
        json.key = key;
        json.title = title;
        json.data = data;
        return json;
    }

    render() {
        const columns = [
            {
                title: 'title',
                dataIndex: 'title',
                key: '1',
                render: (value, row, index) => {
                    const obj = {
                        children: value,
                        props: {}
                    }
                    const length = this.state.listData.length
                    if (index === 0) {
                        obj.props.rowSpan = length - 1
                    }
                    if (index >= 1 && index < length - 1) {
                        obj.props.rowSpan = 0
                    }
                    return obj
                }
            },
            {
                title: 'data',
                dataIndex: 'data',
                key: '2',
                render: (text, index) => {
                    // return index > 9 ? <a target="_blank" href={`/#/main/info/subject/${text}`}>{text}</a> : { text }
                    return <a target="_blank" href={`/#/main/info/subject/${text}`}>{text}</a>
                }
            }
        ]
        return (
            <div style={{width: '400px', height: '400px'}}>
                <Map amapkey={'0c6489213dfe2f86a2c314403cc266ad'} center={[121.48, 31.22]}/>
                <Table
                    dataSource={this.state.listData}
                    columns={columns}
                    bordered
                    pagination={false}
                />
            </div>
        );
    }
}

export default MapTest;

